package com.li.springbootproject.config.i18n;

import java.util.Locale;

import com.lidong.toolkit.constant.LogConst;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.ReloadableResourceBundleMessageSource;

/**
 * @author LiDong
 * @version 1.0.0
 * @createTime 2/21/2022 8:29 PM
 */
@Configuration
public class I18nConfig {

    private static final Logger logger = LoggerFactory.getLogger(I18nConfig.class);

    /**
     * MessageSource Bean
     *
     * @return MessageSource
     */
    @Bean
    public MessageSource messageSource() {
        logger.info(LogConst.LOG_SUCCESS_PREFIX + "MessageSource 注册成功！");
        ReloadableResourceBundleMessageSource source = new ReloadableResourceBundleMessageSource();
        source.setUseCodeAsDefaultMessage(true);
        source.setDefaultLocale(Locale.CHINA);
        source.setBasename("classpath:messages");
        source.setDefaultEncoding("utf-8");
        return source;
    }

}
